<template>
	<div class="components-container">
        <!-- 新增 -->
        <sweet-modal ref="dialog" class="dialog">
            <h3>{{title}}</h3>
            <div style=" height:150px; margin:30px 50px">
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <el-input v-model="Data.SICNAME" ></el-input>
                        </div>
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                             <el-select v-model="Data.SICSTATUS" placeholder="请选择状态"  style="width:100%">
                                <el-option  key="A" label="正常" value="A"></el-option>
                                 <el-option  key="A" label="禁用" value="B"></el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-inline">
                            <el-input v-model="Data.SICNUM" ></el-input>
                        </div>
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input v-model="Data.SICREMARK" ></el-input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
                <el-button type="primary" @click="submit" :loading="this.$store.state.isloading">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal ref="dialogInfo" class="dialog">
            <h3>{{title}}</h3>
            <div style=" height:150px; margin:30px 50px">
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <el-input v-model="Data.SICNAME" readonly></el-input>
                        </div>
                        <label class="layui-form-label">状态</label>
                         <div class="layui-input-inline">
                            <el-input v-model="Data.SICSTATUS"  style="width:100%" readonly></el-input>
                        </div>

                        <!-- <div class="layui-input-inline">
                             <el-select v-model="Data.SICSTATUS" placeholder="请选择状态"  style="width:100%" disabled>
                                <el-option  key="A" label="正常" value="A"></el-option>
                                 <el-option  key="A" label="禁用" value="B"></el-option>
                            </el-select>
                        </div> -->
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-inline">
                            <el-input v-model="Data.SICNUM" readonly></el-input>
                        </div>
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input v-model="Data.SICREMARK" readonly></el-input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
            </div>
        </sweet-modal>
	</div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
import { manage } from "@/mixins/managePage.js";
const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "serviceTypesManageMain",
  props: {
    orderType: {
      type: String,
      default() {
        return ADD;
      }
    }
  },
  data() {
    return {
      title: null,
      Data: {}
    };
  },
  methods: {
    //功能操作
    open(order, id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "服务种类新增";
          this.initSelectData();
          this.$refs.dialog.open();
          break;
        case MODIFY:
          this.title = "服务种类修改";
          this.initSelectData();
          this.dataInfo(id);
          this.$refs.dialog.open();
          break;
        case DELETE:
          this.dataDelete(id);
          break;
        case INFO:
          this.title = "服务种类详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
        default:
      }
    },
    //提交
    submit() {
      this.$store.state.isloading = true;
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },
    //新增
    dataAdd() {
      let Data = JSON.parse(JSON.stringify(this.Data));
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().Servicecategory.Create,
        res => {
          this.$refs.dialog.close();
          this.$message({
            type: "success",
            message: "新增成功!"
          });
          this.loading = false;
          this.refreshData();
        },
        res => {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
      );
    },
    //修改
    dataModify() {
      let Data = JSON.parse(JSON.stringify(this.Data));
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().Servicecategory.Modify,
        res => {
          this.$refs.dialog.close();
          this.$message({
            type: "success",
            message: "修改成功!"
          });
          this.refreshData();
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //删除
    dataDelete(id) {
      let Data = {
        SICID: id
      };
      this.$confirm("此操作将永久删除该服务种类信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        apiBase.DoService(
          Data,
          apiBase.getApiAdress().Servicecategory.Delete,
          res => {
            this.refreshData();
            this.$message({
              message: "删除服务种类成功！",
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    //详情
    dataInfo(id) {
      let Data = {
        SICID: id
      };
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().Servicecategory.Detail,
        res => {
          this.Data = res.data.content;
          this.Data.SICID = id;
        }
      );
    },
    //数据重置
    dataRepeat() {
      this.Data = {};
    },
    initSelectData() {},
    refreshData() {
      this.$emit("refreshData");
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    }
  },
  mounted() {},
  components: {
    sweetModal
  }
};
</script>